package com.jd.webapp.portal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jd.goods.pojo.GoodsDescription;
import com.jd.webapp.portal.pojo.GoodsVo;
import com.jd.webapp.portal.service.GoodsServiceDto;

@Controller
public class GoodsController {
	@Autowired
	private GoodsServiceDto goodsServiceDto;
	
	@RequestMapping("/goods/{id}")
	public String getgoodsById(@PathVariable long id,Model model){
		try {
			GoodsVo goods = goodsServiceDto.getGoodsById(id);
			model.addAttribute("goods", goods);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "goods";
	}
	
	@RequestMapping(value="/goods/desc/{goodsid}",produces=MediaType.TEXT_HTML_VALUE+";charset=utf-8")
	public @ResponseBody String getgoodsDescBygoodsId(@PathVariable long goodsid){
		try {
			GoodsDescription goods = goodsServiceDto.getGoodsDescByGoodsId(goodsid);
			return goods.getGoodsDesc();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	@RequestMapping(value="/goods/spec/{goodsid}",produces=MediaType.TEXT_HTML_VALUE+";charset=utf-8")
	public @ResponseBody String getgoodsParamBygoodsId(@PathVariable long goodsid){
		try {
			String param = goodsServiceDto.getGoodsSpecByGoodsId(goodsid);
			return param;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
